<?php
/**
 * @package WordPress
 * @subpackage desire
 */
?>
<?php
global $desireoptions;
?>
<?php if(!have_posts()) : ?>
    <div id="post-0" class="post error404 not-found">
        <h2 class="entry-title"><?php _e('Entry not found','desire'); ?></h2>
        <div class="entry-content">
            <p><?php _e('Oops no entries found. Try using the search!','desire'); ?></p>
            <p><?php get_search_form(); ?></p>
        </div>
    </div>
<?php endif; ?>
<?php while(have_posts()) : the_post(); ?>
    <?php /* For gallery posts */ ?>
    <?php if((function_exists('get_post_format') && 'gallery' == get_post_format($post->ID)) || in_category(_x('gallery','gallery category slug','desire'))): ?>
    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'desire' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
        <div class="entry-meta">
            <span class="entry-date"><a href="<?php the_permalink(); ?>"><?php /* translators: draft saved date format, see http://php.net/date */ the_time(__('M jS, Y', 'desire' )); ?></a></span>
            <span class="entry-comments"><?php comments_popup_link( __( 'Leave a comment', 'desire' ), __( '1 Comment', 'desire' ), __( '% Comments', 'desire' ) ); ?><?php edit_post_link( __( 'Edit', 'desire' ), '<span class="meta-sep">|</span><span class="edit-link">', '</span>' ); ?></span>
        </div>
        <div class="entry-content">
            <?php if(post_password_required()): ?>
                <?php the_content(); ?>
            <?php else: ?>
                <?php
                    $images = get_children( array( 'post_parent' => $post->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => 999 ) );
                    if($images):
			$total_images = count( $images );
                        $image = array_shift( $images );
			$image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail' );
		?>
                <div class="gallery-thumb">
                    <a class="size-thumbnail" href="<?php the_permalink(); ?>"><?php echo $image_img_tag; ?></a>
                </div>
                <p><em><?php printf(_n('This gallery contains <a %1$s>%2$s photo</a>.', 'This gallery contains <a %1$s>%2$s photos</a>.', $total_images, 'desire'),'href="'.get_permalink().'"title="'.sprintf(esc_attr__('Permalink to %s', 'desire'), the_title_attribute('echo=0')).'" rel="bookmark"', number_format_i18n($total_images)); ?></em></p>
                <?php endif; ?>
                <?php the_excerpt(); ?>
            <?php endif; ?> <!-- end of password required if -->
        </div>
        <div class="entry-tags">
            <?php if ( function_exists( 'get_post_format' ) && 'gallery' == get_post_format( $post->ID ) ) : ?>
	    <a href="<?php echo get_post_format_link( 'gallery' ); ?>" title="<?php esc_attr_e( 'View Galleries', 'desire' ); ?>"><?php _e( 'More Galleries', 'desire' ); ?></a>
	    <?php elseif ( in_category( _x( 'gallery', 'gallery category slug', 'desire' ) ) ) : ?>
	    <a href="<?php echo get_term_link( _x( 'gallery', 'gallery category slug', 'desire' ), 'category' ); ?>" title="<?php esc_attr_e( 'View posts in the Gallery category', 'desire' ); ?>"><?php _e( 'More Galleries', 'desire' ); ?></a>
	    <?php endif; ?>
        </div>
    </div>
    <?php else: ?>
    <?php /* For all other posts */ ?>
    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'desire' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
        <div class="entry-meta">
            <span class="entry-date"><a href="<?php the_permalink(); ?>"><?php /* translators: draft saved date format, see http://php.net/date */ the_time(__('M jS, Y', 'desire' )); ?></a></span>
            <span class="entry-comments"><?php comments_popup_link( __( 'Leave a comment', 'desire' ), __( '1 Comment', 'desire' ), __( '% Comments', 'desire' ) ); ?><?php edit_post_link( __( 'Edit', 'desire' ), '<span class="meta-sep">|</span><span class="edit-link">', '</span>' ); ?></span>
        </div>
        <?php if($desireoptions['show_category_front']): ?>
        <div class="entry-cat">
            <span class="entry-categories"><?php _e('Posted in: ','desire'); ?><?php echo get_the_category_list(', '); ?></span>
        </div>
        <?php endif; ?>
        <div class="entry-content">
            <?php the_content( __( 'Read more', 'desire' ) ); ?>
            <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'desire' ), 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
        </div>
        <?php
            $tags_list = get_the_tag_list( '', ', ' );
            if (trim($tags_list) !="" and $desireoptions['show_tags_front']):
        ?>
        <div class="entry-tags"><span class="tag-links"><?php _e('Tagged in:','desire'); ?> <?php echo $tags_list; ?></span></div>
        <?php endif; ?> <!-- end of tag list if -->        
    </div>
    <?php endif; ?>
<?php endwhile; ?>
<?php desire_get_pagination(); ?>